package  
{
	import events.NavigationEvent;
	import screens.InGame;
	import screens.Splash;
	import starling.display.Sprite;
	import starling.text.TextField;
	import starling.events.Event;
	
	/**
	 * The Game class
	 * @author Epixcs
	 */
	
	public class Game extends Sprite
	{
		private var m_sreenSplash:Splash 	= null; // The splash screen
		private var m_screenInGame:InGame	= null; // The ingame screen
		
		/*************************************************************************/
		
		/**
		 * Main game constructor
		 */
		public function Game() 
		{
			// super it
			super();
			
			// listen for stage adding
			this.addEventListener( Event.ADDED_TO_STAGE, this._onAddedToStage );
		}
		
		/*************************************************************************/
		
		// called when this is added to stage
		private function _onAddedToStage(e:Event):void 
		{
			// remove listener
			this.removeEventListener( Event.ADDED_TO_STAGE, _onAddedToStage );
			
			// add screen changing event listener
			this.addEventListener( NavigationEvent.CHANGE_SCREEN, this._onScreenChanged );
			
			// create the screens
			this.m_screenInGame = new InGame;
			this.m_sreenSplash	= new Splash;
			
			// add them to stage
			this.addChild( this.m_screenInGame );
			this.addChild( this.m_sreenSplash );
			
			// initialize them
			this.m_screenInGame.disposeTemporarily();
			this.m_sreenSplash.initialize();
		}
		
		// called when the game screen has changed
		private function _onScreenChanged( e:NavigationEvent ):void 
		{
			switch( e.data.id )
			{
				case "play" :
					this.m_sreenSplash.disposeTemporarily();
					this.m_screenInGame.initialize();
					break;
			}
		}
		
	}

}